<html>
<head><meta charset="utf-8"><title>Unwind paths in MIR · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html">Unwind paths in MIR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244694711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244694711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244694711">(Jul 02 2021 at 12:26)</a>:</h4>
<p>Hey, when writing this post <a href="https://users.rust-lang.org/t/how-can-std-thread-join-catch-panics/61805/5?u=yandros">https://users.rust-lang.org/t/how-can-std-thread-join-catch-panics/61805/5?u=yandros</a>, with the source code in the playground (minus the <code>main()</code> function, just the <code>lib</code> definition), I observed that the function <code>drop_last()</code> did not feature an unwind path in the <code>--unpretty=mir{,-cfg}</code>-emitted MIR:</p>
<p><a href="/user_uploads/4715/y18IeAbaHRUuxEh_YqS-j0wq/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/y18IeAbaHRUuxEh_YqS-j0wq/image.png" title="image.png"><img src="/user_uploads/4715/y18IeAbaHRUuxEh_YqS-j0wq/image.png"></a></div><p>But that <code>drop::&lt;Option&lt;T&gt;&gt;(</code> can very well panic! I noticed that if I disabled the <code>mir-opt-level</code> down to 0, the <code>unwind</code> path was there.</p>
<p><a href="/user_uploads/4715/Uj-TimpF_qsv2eTBBhbsMlbJ/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/Uj-TimpF_qsv2eTBBhbsMlbJ/image.png" title="image.png"><img src="/user_uploads/4715/Uj-TimpF_qsv2eTBBhbsMlbJ/image.png"></a></div><ul>
<li><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=1d482dc2be51447d4dc5ff5370b88a30">Playground</a></li>
</ul>
<p>Why that difference? Is that a bug of some MIR optimization, or is there something obvious I am missing about the <code>--unpretty</code>-generated MIR pseudo code?</p>



<a name="244695291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695291">(Jul 02 2021 at 12:31)</a>:</h4>
<p>these look equivalent</p>



<a name="244695312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695312">(Jul 02 2021 at 12:31)</a>:</h4>
<p>if the <code>unwind</code> edge is missing it acts like a <code>resume</code> terminator</p>



<a name="244695325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695325">(Jul 02 2021 at 12:31)</a>:</h4>
<p>(yes this is subtle)</p>



<a name="244695592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695592">(Jul 02 2021 at 12:34)</a>:</h4>
<p>Ohhh thanks, I was wondering if there was something like that. Is it possible to force the display of <code>unwind -&gt; resume</code> paths? I find them very useful, both</p>
<ul>
<li>when teaching something, as in that post,</li>
<li>and sometimes for my own actual code, to make sure I did not overlook possible unwind paths</li>
</ul>



<a name="244695650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695650">(Jul 02 2021 at 12:34)</a>:</h4>
<p>no, they will be displayed only when present</p>



<a name="244695692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244695692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244695692">(Jul 02 2021 at 12:35)</a>:</h4>
<p>but I wouldn't mind an indicator for <code>None</code> unwind edges that has a <code>resume</code> label on it or something</p>



<a name="244697094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697094">(Jul 02 2021 at 12:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/122651-general/topic/Unwind.20paths.20in.20MIR/near/244695692">said</a>:</p>
<blockquote>
<p>but I wouldn't mind an indicator for <code>None</code> unwind edges that has a <code>resume</code> label on it or something</p>
</blockquote>
<p>Would that be a <code>return [or resume-on-unwind]</code> label on a "simplified" edge rather than the current terse <code>return</code>, or the "cumbersome" <code>return…</code>-&amp;-<code>unwind-to-resume</code> double branch?</p>



<a name="244697250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697250">(Jul 02 2021 at 12:50)</a>:</h4>
<p>Something like:<br>
<a href="/user_uploads/4715/5roqIICF-pKa6ya4Ql4feLR4/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/5roqIICF-pKa6ya4Ql4feLR4/image.png" title="image.png"><img src="/user_uploads/4715/5roqIICF-pKa6ya4Ql4feLR4/image.png"></a></div>



<a name="244697318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697318">(Jul 02 2021 at 12:50)</a>:</h4>
<p>I'd prefer two separate edges, with the unwind edge pointing "nowhere", if that's possible</p>



<a name="244697361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697361">(Jul 02 2021 at 12:51)</a>:</h4>
<p>but it probably doesn't matter too much</p>



<a name="244697469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697469">(Jul 02 2021 at 12:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/122651-general/topic/Unwind.20paths.20in.20MIR/near/244697318">said</a>:</p>
<blockquote>
<p>I'd prefer two separate edges, with the unwind edge pointing "nowhere", if that's possible</p>
</blockquote>
<p>Oh yeah, that's even better. I don't really care what happens after the <code>unwind</code> edge, I would just want <em>some</em> way to know about an unwinding branch there <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="244697602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697602">(Jul 02 2021 at 12:53)</a>:</h4>
<p>From the perspective of the personality function there isn't even an unwinding branch there. There is just no cleanup information at that specific point, so it tells the unwinder that no cleanup is necessary and that it should check with the next frame.</p>



<a name="244697722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697722">(Jul 02 2021 at 12:54)</a>:</h4>
<div class="codehilite" data-code-language="Graphviz"><pre><span></span><code><span class="w">    </span><span class="nt">bb1__0_13</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nt">bb2__0_13</span><span class="w"> </span><span class="p">[</span><span class="na">label</span><span class="p">=</span><span class="s2">"return"</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Show the unwind branch</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="na">rank</span><span class="p">=</span><span class="s">same</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="nt">bb1__0_13</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nt">bb1__0_13_unwind</span><span class="w"> </span><span class="p">[</span><span class="na">label</span><span class="p">=</span><span class="s2">"unwind"</span><span class="p">]</span><span class="w"></span>
<span class="w">        </span><span class="nt">bb1__0_13_unwind</span><span class="w"> </span><span class="p">[</span><span class="na">style</span><span class="w"> </span><span class="p">=</span><span class="w"> </span><span class="s">invis</span><span class="p">,</span><span class="w"> </span><span class="na">label</span><span class="p">=</span><span class="s2">""</span><span class="p">,</span><span class="w"> </span><span class="na">width</span><span class="p">=</span><span class="m">0</span><span class="p">]</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="/user_uploads/4715/JQJTvS0GDJPT2i3B-1nVfBP2/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/JQJTvS0GDJPT2i3B-1nVfBP2/image.png" title="image.png"><img src="/user_uploads/4715/JQJTvS0GDJPT2i3B-1nVfBP2/image.png"></a></div>



<a name="244697824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Unwind%20paths%20in%20MIR/near/244697824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Unwind.20paths.20in.20MIR.html#244697824">(Jul 02 2021 at 12:55)</a>:</h4>
<p>yeah that looks good</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>